package Coffee.dao;

import Coffee.bean.Coffee;
import Coffee.util.Cbase;

import java.util.List;

public class CoffeeDaoImpl extends Cbase implements CoffeeDao{
    @Override
    public int insertCoffee(Coffee coffee) {
        String sql = "insert into tb_coffee values (?,?,?,?)";
        return update(sql, coffee.getCofid(), coffee.getCofname(), coffee.getCofprice(), coffee.getState());

    }

    @Override
    public int delbyname(String cofname) {
        String sql = "delete from tb_coffee where cofname = ?";
        return update(sql,cofname);

    }

    @Override
    public Coffee selectbyname(String cofname) {
        String sql = "select * from tb_coffee where cofname = ?";
        return getOne(Coffee.class, sql, cofname);
    }

    @Override
    public int updateCofbyname(String cofname,int cofprice,String state) {
        String sql = "update tb_coffee set cofprice = ? ,state = ? where cofname = ?";
        return update(sql,cofprice,state,cofname);
    }

    @Override
    public List<Coffee> selectAll() {
        String sql = "select * from tb_coffee ";
        return getAll(Coffee.class,sql);
    }

    @Override
    public List<Coffee> selectlikaname(String cofname) {
        String sql = "select * from tb_coffee where cofname like ?";
        return getAll(Coffee.class, sql, "%"+cofname+"%");
    }
}
